<?php
/**
 * CreateTime: 2023/7/13 17:27
 */

namespace App\Func;

use App\Http\pkConfig\login\PkLoginConfigGet;
use Illuminate\Support\Facades\Redis;


class AdminTokenFunc
{
    public function getUkTInfo(){
        $requestId = RequestFunc::getHeaderParams("U-TK");

        // 通过Rsa解密获取redis中正确的key
        $encryptionFunc = new EncryptionFunc();
        $adminLoginPkConfig = new PkLoginConfigGet();
        $redisKey = $encryptionFunc->rsaToBase64Decode($adminLoginPkConfig->getPrKey(),$requestId);
        if(!$redisKey){
            return [
                'error' => 'notRedisKey'
            ];
        }
        // 如果存在则给其延时
        $req = Redis::expire($redisKey, 3600);
        $redisInfo = unserialize(Redis::get($redisKey));
        if(!$redisInfo){
            return [
                'error' => 'redisValueError'
            ];
        }

        // 校验IP
        $ip = RequestFunc::getIP();

        if($ip!=$redisInfo['ip']){
            return [
                'error' => 'ipError'
            ];
        }

        return $redisInfo['admin_info'];
    }
}